<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Drawer 抽屉 | MyUI 4.x</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="icon" href="/my/favicon.ico">
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?c4e5f73318b5cb0c389e3d9a05f831cc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
    <meta name="description" content="MyUI是美亚柏科旗下新德汇出品的Web前端一站式项目工程框架，专注于公检法行业中台系统快速搭建，框架已在多个项目实战检验。">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <link rel="preload" href="/my/assets/css/0.styles.3b7da768.css" as="style"><link rel="preload" href="/my/assets/js/app.145deadf.js" as="script"><link rel="preload" href="/my/assets/js/546.c48d7d92.js" as="script"><link rel="preload" href="/my/assets/js/1288.fdb6ea55.js" as="script"><link rel="preload" href="/my/assets/js/974.ffa6c050.js" as="script">
    <link rel="stylesheet" href="/my/assets/css/0.styles.3b7da768.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/my/" class="home-link router-link-active"><img src="/my/img/logo.png" alt="MyUI 4.x" class="logo"> <span class="site-name can-hide">MyUI 4.x</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Basic</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Form</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Data</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Notice</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Navigation</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Others</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/my/element/backtop.html" class="sidebar-link">Backtop 回到顶部</a></li><li><a href="/my/element/calendar.html" class="sidebar-link">Calendar calendar</a></li><li><a href="/my/element/card.html" class="sidebar-link">Card 卡片</a></li><li><a href="/my/element/carousel.html" class="sidebar-link">Carousel 走马灯</a></li><li><a href="/my/element/collapse.html" class="sidebar-link">Collapse 折叠面板</a></li><li><a href="/my/element/dialog.html" class="sidebar-link">Dialog 对话框</a></li><li><a href="/my/element/divider.html" class="sidebar-link">Divider 分割线</a></li><li><a href="/my/element/drawer.html" aria-current="page" class="active sidebar-link">Drawer 抽屉</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/element/drawer.html#基本用法" class="sidebar-link">基本用法</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#不添加-title" class="sidebar-link">不添加 Title</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#自定义内容" class="sidebar-link">自定义内容</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#多层嵌套" class="sidebar-link">多层嵌套</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#drawer-attributes" class="sidebar-link">Drawer Attributes</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#drawer-slot" class="sidebar-link">Drawer Slot</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#drawer-methods" class="sidebar-link">Drawer Methods</a></li><li class="sidebar-sub-header"><a href="/my/element/drawer.html#drawer-events" class="sidebar-link">Drawer Events</a></li></ul></li><li><a href="/my/element/image.html" class="sidebar-link">Image 图片</a></li><li><a href="/my/element/infiniteScroll.html" class="sidebar-link">InfiniteScroll 无限滚动</a></li><li><a href="/my/element/popconfirm.html" class="sidebar-link">Popconfirm 气泡确认框</a></li><li><a href="/my/element/popover.html" class="sidebar-link">Popover 弹出框</a></li><li><a href="/my/element/timeline.html" class="sidebar-link">Timeline 时间线</a></li><li><a href="/my/element/tooltip.html" class="sidebar-link">Tooltip 文字提示</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="drawer-抽屉"><a href="#drawer-抽屉" class="header-anchor">#</a> Drawer 抽屉</h1> <p>有些时候, <code>Dialog</code> 组件并不满足我们的需求, 比如你的表单很长, 亦或是你需要临时展示一些文档, <code>Drawer</code> 拥有和 <code>Dialog</code> 几乎相同的 API, 在 UI 上带来不一样的体验.</p> <h2 id="基本用法"><a href="#基本用法" class="header-anchor">#</a> 基本用法</h2> <p>呼出一个临时的侧边栏, 可以从多个方向呼出</p> <!----><h2 id="不添加-title"><a href="#不添加-title" class="header-anchor">#</a> 不添加 Title</h2> <p>当你不需要标题到时候, 你还可以去掉标题</p> <!----><h2 id="自定义内容"><a href="#自定义内容" class="header-anchor">#</a> 自定义内容</h2> <p>和 <code>Dialog</code> 组件一样, <code>Drawer</code> 同样可以在其内部嵌套各种丰富的操作</p> <!----><h2 id="多层嵌套"><a href="#多层嵌套" class="header-anchor">#</a> 多层嵌套</h2> <p><code>Drawer</code> 组件也拥有多层嵌套的方法</p> <!----><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>Drawer 的内容是懒渲染的，即在第一次被打开之前，传入的默认 slot 不会被渲染到 DOM 上。因此，如果需要执行 DOM 操作，或通过 <code>ref</code> 获取相应组件，请在 <code>open</code> 事件回调中进行。</p></div> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>Drawer 提供一个 <code>destroyOnClose</code> API, 用来在关闭 Drawer 时销毁子组件内容, 例如清理表单内的状态, 在必要时可以将该属性设置为 <strong>true</strong> 用来保证初始状态的一致性</p></div> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>如果 <code>visible</code> 属性绑定的变量位于 Vuex 的 store 内，那么 <code>.sync</code> 不会正常工作。此时需要去除 <code>.sync</code> 修饰符，同时监听 Drawer 的 <code>open</code> 和 <code>close</code> 事件，在事件回调中执行 Vuex 中对应的 mutation 更新 <code>visible</code> 属性绑定的变量的值。</p></div> <h2 id="drawer-attributes"><a href="#drawer-attributes" class="header-anchor">#</a> Drawer Attributes</h2> <table><thead><tr><th>参数</th> <th>说明</th> <th>类型</th> <th>可选值</th> <th>默认值</th></tr></thead> <tbody><tr><td>append-to-body</td> <td>Drawer 自身是否插入至 body 元素上。嵌套的 Drawer 必须指定该属性并赋值为 true</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>before-close</td> <td>关闭前的回调，会暂停 Drawer 的关闭</td> <td>function(done)，done 用于关闭 Drawer</td> <td>—</td> <td>—</td></tr> <tr><td>close-on-press-escape</td> <td>是否可以通过按下 ESC 关闭 Drawer</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>custom-class</td> <td>Drawer 的自定义类名</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>destroy-on-close</td> <td>控制是否在关闭 Drawer 之后将子元素全部销毁</td> <td>boolean</td> <td>-</td> <td>false</td></tr> <tr><td>modal</td> <td>是否需要遮罩层</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>modal-append-to-body</td> <td>遮罩层是否插入至 body 元素上，若为 false，则遮罩层会插入至 Drawer 的父元素上</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>direction</td> <td>Drawer 打开的方向</td> <td>Direction</td> <td>rtl / ltr / ttb / btt</td> <td>rtl</td></tr> <tr><td>show-close</td> <td>是否显示关闭按钮</td> <td>boolean</td> <td>—</td> <td>true</td></tr> <tr><td>size</td> <td>Drawer 窗体的大小, 当使用 <code>number</code> 类型时, 以像素为单位, 当使用 <code>string</code> 类型时, 请传入 'x%', 否则便会以 <code>number</code> 类型解释</td> <td>number / string</td> <td>-</td> <td>'30%'</td></tr> <tr><td>title</td> <td>Drawer 的标题，也可通过具名 slot （见下表）传入</td> <td>string</td> <td>—</td> <td>—</td></tr> <tr><td>visible</td> <td>是否显示 Drawer，支持 .sync 修饰符</td> <td>boolean</td> <td>—</td> <td>false</td></tr> <tr><td>wrapperClosable</td> <td>点击遮罩层是否可以关闭 Drawer</td> <td>boolean</td> <td>-</td> <td>true</td></tr> <tr><td>withHeader</td> <td>控制是否显示 header 栏, 默认为 true, 当此项为 false 时, title attribute 和 title slot 均不生效</td> <td>boolean</td> <td>-</td> <td>true</td></tr></tbody></table> <h2 id="drawer-slot"><a href="#drawer-slot" class="header-anchor">#</a> Drawer Slot</h2> <table><thead><tr><th>name</th> <th>说明</th></tr></thead> <tbody><tr><td>—</td> <td>Drawer 的内容</td></tr> <tr><td>title</td> <td>Drawer 标题区的内容</td></tr></tbody></table> <h2 id="drawer-methods"><a href="#drawer-methods" class="header-anchor">#</a> Drawer Methods</h2> <table><thead><tr><th>name</th> <th>说明</th></tr></thead> <tbody><tr><td>closeDrawer</td> <td>用于关闭 Drawer, 该方法会调用传入的 <code>before-close</code> 方法</td></tr></tbody></table> <h2 id="drawer-events"><a href="#drawer-events" class="header-anchor">#</a> Drawer Events</h2> <table><thead><tr><th>事件名称</th> <th>说明</th> <th>回调参数</th></tr></thead> <tbody><tr><td>open</td> <td>Drawer 打开的回调</td> <td>—</td></tr> <tr><td>opened</td> <td>Drawer 打开动画结束时的回调</td> <td>—</td></tr> <tr><td>close</td> <td>Drawer 关闭的回调</td> <td>—</td></tr> <tr><td>closed</td> <td>Drawer 关闭动画结束时的回调</td> <td>—</td></tr></tbody></table></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/my/element/divider.html" class="prev">
        Divider 分割线
      </a></span> <span class="next"><a href="/my/element/image.html">
        Image 图片
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/my/assets/js/app.145deadf.js" defer></script><script src="/my/assets/js/546.c48d7d92.js" defer></script><script src="/my/assets/js/1288.fdb6ea55.js" defer></script><script src="/my/assets/js/974.ffa6c050.js" defer></script>
  </body>
</html>
